function openReservePopupByClick() {
	var dateFromObj	= document.getElementById("dateFromReserv");
	var dateToObj	= document.getElementById("dateToReserv");
    var popupUrl 	= document.getElementById("reserveByPopupPath");

    if(dateFromObj.value == ""){
        alert("Please input date from");
        dateFromObj.focus();
        return;
    }else if(dateToObj.value == ""){
        alert("Please input date to");
        dateFromObj.focus();
        return;
    }
    var params 		= "?dateFromPopup="+dateFromObj.value+"&dateToPopup="+dateToObj.value;
    isOpennerFlag 	= true; 
    showPopup(popupUrl.value + params, 'ReservePopup', 150, 400);            
}   

function openReservePopupByDoubleClick(obj) {
	var day			= obj.getElementsByTagName("tr")[0].getElementsByTagName("td")[0].innerText;
	var month		= document.getElementById("monthReserv").value;
	var year		= document.getElementById("yearReserv").value;
	var date		= (day.length==1?"0"+day:day)+"/"+(month.length==1?"0"+month:month)+"/"+year;
    var popupUrl 	= document.getElementById("reserveByPopupPath");
    var params 		= "?dateFromPopup="+date;

    isOpennerFlag 	= true; 
    showPopup(popupUrl.value + params, 'ReservePopup', 150, 400);            
}   
function toReserveInfo(){
	var btnObj = document.getElementById("btnToReserveInfo");
	btnObj.click();
}
function toReserveInfoRoom(){
	var btnObj = document.getElementById("btnToReserveInfoRoom");
	btnObj.click();
}
function validateDateFromReserv(obj) {
	if(validateDateFormat(obj)){
		var dateFrom 	= document.getElementById("dateFromReserv");
		var dateTo 		= document.getElementById("dateToReserv");
		
		if(dateFrom.value != "" && dateTo.value != ""){
			var _day		= calculateBetweenDate(dateFrom.value, dateTo.value)+1;
			if(_day <= 0){
				alert("Please input dateFrom less than dateTo.");
				dateFrom.value = "";
				dateFrom.focus();
			}
		}		
	}
}
function validateDateToReserv(obj) {
	if(validateDateFormat(obj)){
		var dateFrom 	= document.getElementById("dateFromReserv");
		var dateTo 		= document.getElementById("dateToReserv");
		
		if(dateFrom.value != "" && dateTo.value != ""){
			var _day		= calculateBetweenDate(dateFrom.value, dateTo.value)+1;
			if(_day <= 0){
				alert("Please input dateTo more than dateFrom.");
				dateTo.value = "";
				dateTo.focus();
			}
		}
	}
}

function openGroupResultPopupByClick(groupId, groupName) {
	var group		= document.getElementById("groupReserv").value;
	var status		= document.getElementById("groupStatusReserv").value;
    if(groupId == '') groupId = group;
    
    document.getElementById("groupResultDataTypePopup").value	= '1';
    document.getElementById("groupResultPopup").value 			= groupId;
    document.getElementById("groupResultNamePopup").value 		= groupName;
    document.getElementById("groupResultStatusPopup").value 	= status;
    var params 		= "?groupResultPopup="+groupId+"&groupResultStatusPopup="+status;

    isdnSendRequest("reserveOverview_checkGroupJSON.action", params , "POST", callbackGroupResultPopup);    
}  

function openCustomerResultPopupByClick(customerId, customerName) {
	var group		= document.getElementById("customerReserv").value;
	var status		= document.getElementById("customerStatusReserv").value;
    if(customerId == '') customerId = group;
    
    document.getElementById("groupResultDataTypePopup").value	= '2';
    document.getElementById("groupResultPopup").value 			= customerId;
    document.getElementById("groupResultNamePopup").value 		= customerName;
    document.getElementById("groupResultStatusPopup").value 	= status;
    var params 		= "?groupResultPopup="+customerId+"&groupResultStatusPopup="+status;

    isdnSendRequest("reserveOverview_checkCustomerJSON.action", params , "POST", callbackGroupResultPopup);    
}  

function openRoomResultPopupByClick(roomId, roomName) {
	var group		= document.getElementById("roomReserv").value;
	var status		= document.getElementById("roomStatusReserv").value;
    if(roomId == '') roomId = group;
    
    document.getElementById("groupResultDataTypePopup").value	= '3';
    document.getElementById("groupResultPopup").value 			= roomId;
    document.getElementById("groupResultNamePopup").value 		= roomName;
    document.getElementById("groupResultStatusPopup").value 	= status;
    var params 		= "?groupResultPopup="+roomId+"&groupResultStatusPopup="+status;

    isdnSendRequest("reserveOverview_checkRoomJSON.action", params , "POST", callbackGroupResultPopup);    
}  

callbackGroupResultPopup = function() {
    var ready = req.readyState;
    //  console.debug(ready);
    var jsonObject=null;
    if ( ready == 4 ){
        if(req.status == 200) {
            jsonObject=eval( "("+ req.responseText +")" );
            if(jsonObject.object.data['com.appsindy.reserv.vo.Info']){         	
                var detail  = jsonObject.object.data['com.appsindy.reserv.vo.Info'];
                var size 	= detail.length;
                if(size > 1){
                	var dataType	= document.getElementById("groupResultDataTypePopup").value;
                	var group		= document.getElementById("groupResultPopup").value;
                	var groupName	= document.getElementById("groupResultNamePopup").value;
                	var status		= document.getElementById("groupResultStatusPopup").value;
                    var popupUrl 	= "";
                    if(dataType == "1"){
                    	popupUrl	= document.getElementById("groupResultPopupPath");
                    }else if(dataType == "2"){
                    	popupUrl	= document.getElementById("customerResultPopupPath");
                    }else if(dataType == "3"){
                    	popupUrl	= document.getElementById("roomResultPopupPath");
                    }
                    var params 		= "?groupResultPopup="+group+"&groupResultNamePopup="+groupName+"&groupResultStatusPopup="+status;
                    isOpennerFlag 	= true; 
                    showPopup(popupUrl.value + params, 'GroupResultPopup', 400, 600);
                    //showModalDialogPopup(popupUrl.value + params, 400, 600);
                }else{
        			var frmReserveInfoRoom 							= document.getElementById("frmReserveInfoRoom");
        			frmReserveInfoRoom.serviceHeaderIdPopup.value 	= detail.id;
        			frmReserveInfoRoom.groupResultPopup.value		= detail.groupId;
        			toReserveInfoRoom();        			
                }                
            }
        }
    }
};

function btnOverviewGoOnClick(obj){
    url = "reserveOverview_searchCalendar.action";
    document.getElementById("frmSearchTranx").action = url;
    document.getElementById("frmSearchTranx").submit();
}
function btnOverviewRefreshOnClick(obj){
    url = "reserveOverview_execute.action";
    document.getElementById("frmSearchTranx").action = url;
    document.getElementById("frmSearchTranx").submit();
}
function btnOverviewGroupSearchOnClick(obj){
    url = "reserveOverview_searchGroup.action";
    document.getElementById("frmSearchTranx").action = url;
    document.getElementById("frmSearchTranx").submit();
}
function btnOverviewCustomerSearchOnClick(obj){
    url = "reserveOverview_searchCustomer.action";
    document.getElementById("frmSearchTranx").action = url;
    document.getElementById("frmSearchTranx").submit();
}
function btnOverviewRoomSearchOnClick(obj){
    url = "reserveOverview_searchRoom.action";
    document.getElementById("frmSearchTranx").action = url;
    document.getElementById("frmSearchTranx").submit();
}
